package com.rz.htk.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rz.htk.order.entity.OrderRecord;
import com.rz.htk.order.mapper.OrderRecordMapper;
import com.rz.htk.order.service.IOrderRecordService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class OrderRecordServiceImpl extends ServiceImpl<OrderRecordMapper,OrderRecord> implements IOrderRecordService{



    @Override
    public List<OrderRecord> getListRecordByOrderCode(String orderCode) {
        QueryWrapper<OrderRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("commodity_code", orderCode);
        return list(queryWrapper);
    }

    @Override
    public boolean deleteRecord(String orderCode) {
        List<OrderRecord> orderRecordList = getListRecordByOrderCode(orderCode);
        orderRecordList.forEach(orderRecord -> {
            this.removeById(orderRecord.getId());
        });
        return true;
    }

    @Override
    public boolean savaRecord(String orderCode, int state, int crteMngId, String rmk) {
        OrderRecord orderRecord = new OrderRecord();
        orderRecord.setCommodityCode(orderCode);
        orderRecord.setCreationTime(LocalDateTime.now());
        orderRecord.setCrteMngId(crteMngId);
        orderRecord.setState(state);
        orderRecord.setRmk(rmk);
        this.save(orderRecord);
        return true;
    }
}

